﻿using System.Runtime.InteropServices;
using System.Web.UI.WebControls.WebParts;
using System;
using System.Web.UI.WebControls;
using Eneta.Portal.Common;
using Eneta.Portal.Common.Definitions;
using Eneta.Portal.Literature.Controls;

namespace Eneta.Portal.Literature
{
    [Guid("5c042225-ff12-4a47-b815-9c9f87cd1102")]
    public class RandomBookWebPart : WebPart
    {
        protected override void CreateChildControls()
        {
            base.CreateChildControls();

            try
            {
                var control = Page.LoadControl("~/_controltemplates/RandomLiteratureControl.ascx") as RandomLiteratureControl;
                if (control == null)
                    throw new NullReferenceException("Control is missing! ~/_controltemplates/RandomLiteratureControl.ascx");
                control.WebUrl = Webs.Books;
                control.ContentTypeName = "Raamat";
                control.Title = "Raamatud";
                Controls.Add(control);
            }
            catch (Exception ex)
            {
                Logger.LogException(ex);
                var error = new Literal();
                error.Text = ex.Message;
                Controls.Add(error);
            }
        }
    }
}
